using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace LoD.WPClientLibrary.MapEngine {
    public class TileSet {
        public TileSet(Texture2D tileSetTexture) : this(tileSetTexture, 64, 64, 64, 16, 32, 32, new Vector2(19, 39)) { this.TileSetTexture = tileSetTexture; }

        public TileSet(Texture2D tileSetTexture, int tileWidth, int tileHeight, int tileStepX, int tileStepY,
                    int oddRowXOffset, int heightTileOffset, Vector2 originPoint) {
            this.TileWidth = tileWidth;
            this.TileHeight = tileHeight;
            this.TileStepX = tileStepX;
            this.TileStepY = tileStepY;
            this.OddRowXOffset = oddRowXOffset;
            this.HeightTileOffset = heightTileOffset;
            this.OriginPoint = originPoint;
            this.TileSetTexture = tileSetTexture;
        }

        public Texture2D TileSetTexture { get; private set; }
        public int TileWidth { get; private set; }
        public int TileHeight { get; private set; }
        public int TileStepX { get; private set; }
        public int TileStepY { get; private set; }
        public int OddRowXOffset { get; private set; }
        public int HeightTileOffset { get; private set; }
        public Vector2 OriginPoint { get; private set; }

        public Rectangle GetSourceRectangle(int tileIndex) {
            int tileY = tileIndex / (this.TileSetTexture.Width / this.TileWidth);
            int tileX = tileIndex % (this.TileSetTexture.Width / this.TileWidth);

            return new Rectangle(tileX * this.TileWidth, tileY * this.TileHeight, this.TileWidth, this.TileHeight);
        }
    }
}